<?php

namespace app\model;
use think\facade\Db;
use think\facade\Request;
use think\Model;
class department extends Model
{

    function search()
    {
        $key=Request::param('key');
        //  $data=Bookinfo::where("bookname","like","%".$key."%")->paginate(['list_rows'=>4,'query'=>Request::param()]);

        $data=department::withSearch(['departmentname','address'],[
            'departmentname'=>$key,
            'address'=>$key
        ])->paginate(['list_rows'=>3,'query'=>Request::param()]);
//        dump(Db::getlastsql());
        // halt($data->toArray());
        return $data;
    }

    function searchdepartmentnameAttr($q,$v){
        //  halt($q,$v,$d);
        $q->where('departmentname','like','%'.$v.'%');

    }
    function searchaddressAttr($q,$v){
        $q->whereor('address','like','%'.$v.'%');
    }
}